package com.youbug.mall.ware_wms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.common.vo.QueryVo;
import com.youbug.common.vo.R;
import com.youbug.mall.ware_wms.entity.WmsPurchase;
import com.youbug.mall.ware_wms.entity.WmsPurchaseDetail;
import com.youbug.mall.ware_wms.service.IWmsPurchaseDetailService;
import com.youbug.mall.ware_wms.service.IWmsPurchaseService;
import com.youbug.mall.ware_wms.vo.PurchaseDoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 采购信息 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2024-05-05
 */
@RestController
@RequestMapping("/myWmsPurchase")
public class MyWmsPurchaseController {
    @Autowired
    private IWmsPurchaseService wmsPurchaseService;
    @Autowired
    private IWmsPurchaseDetailService purchaseDetailService;


    @PostMapping("/getWmsPurchasePage")
    public R<IPage<WmsPurchase>> getWmsPurchasePage(@RequestBody QueryVo<WmsPurchase> queryVo){

        IPage<WmsPurchase> wmsPurchases = wmsPurchaseService.getWmsPurchasePage(queryVo);

        return R.ok(wmsPurchases);
    }

    @GetMapping("/getPurchaseDetails/{purchaseId}")
    public R<List<WmsPurchaseDetail>> getPurchaseDetails(@PathVariable("purchaseId") Long id){

        List<WmsPurchaseDetail> details = purchaseDetailService.getPurchaseDetails(id);

        return R.ok(details);
    }

    @PostMapping("/receive")
    public R<Boolean> receive(@RequestBody List<Long> ids){

        boolean receive = wmsPurchaseService.receive(ids);

        return  R.ok(receive);
    }

    @PostMapping("/done")
    public R<Boolean> done(@RequestBody PurchaseDoneVo vo){

        boolean receive = wmsPurchaseService.done(vo);

        return  R.ok(receive);
    }
}

